# import csv
import pandas as pd
import numpy as np
import time
from struct import *
import serial

# with open(r"..\csv_fund_quotes\q_217022_债券型-混合债_招商产业债券A.csv", "rt", encoding='UTF-8') as csvfile:
#     reader = csv.reader(csvfile)
#     columns = [(row[2], row[3], row[4]) for row in reader]
#     columns.pop(0)
#
#
# my_columns = []
# for tuples in columns:
#     my_columns.append(tuples[0])
#     my_columns.append(tuples[1])
#     my_columns.append(tuples[2])
#
# column_float = map(float, my_columns)
# my_column = list(column_float)
# print(my_column)

df = pd.read_csv(r"..\csv_fund_quotes\q_217022_债券型-混合债_招商产业债券A.csv", usecols=[2, 3, 4])
mat = np.array(df)

ser = serial.Serial("COM2")
# for i in range(0, len(my_column)-1, 3):
#     data = pack("fffBBBB", my_column[i], my_column[i+1], my_column[i+2], 0x00, 0x00, 0x80, 0x7F)
for i in range(len(mat)):
    data = pack("fffBBBB", *mat[i], 0x00, 0x00, 0x80, 0x7F)
    ser.write(data)
    time.sleep(0.001)
ser.close()



